<template>
	<div class="game-container report-container">
		<div class="view-container dealer-container">
			<div class="params">
				{{ `${$t('dxn.game_rule.game_rules')}` }} -
				{{ `${$t('dxn.game_rule.texas_poker')}` }} / AOF德州
				<el-divider></el-divider>
				<ConfigRule
					:config="texasPokerConfigData.val"
					@cancel="handleTexasPokerCancel"
				/>
			</div>
			<div class="params">
				{{ `${$t('dxn.game_rule.game_rules')}` }} -
				{{ `${$t('dxn.game_rule.short_card')}` }} / AOF短牌
				<el-divider></el-divider>
				<ConfigRule
					:config="shortCardConfigData.val"
					@cancel="handleShortCardCancel"
				/>
			</div>
		</div>
	</div>
</template>
<script>
import ConfigRule from './components/configRule'
import { routerNames } from '@/utils/consts'
export default {
	name: routerNames.quickAddConfig,
	components: {
		ConfigRule
	},
	data() {
		return {
			texasPokerConfigData: { val: [] },
			shortCardConfigData: { val: [] }
		}
	},
	created() {
		this.getRaiseConfig()
	},
	methods: {
		// 格式化配置数据
		formatRaiseConfig(configData, gameType) {
			const configArr = configData
				.filter((item) => item?.gameType === gameType)
				.map((item) => {
					const configVal = item?.val ? JSON.parse(item.val) : []
					const formatItem = {
						id: item.id,
						type: item.raiseType,
						potFill: configVal.map((row) => row?.code).join(',')
					}
					return formatItem
				})
			// 德州扑克
			if (gameType === 2001) {
				this.$set(this.texasPokerConfigData, 'val', configArr)
			}
			// 短牌
			if (gameType === 2002) {
				this.$set(this.shortCardConfigData, 'val', configArr)
			}
		},
		// 获取所有自定义加注配置
		getRaiseConfig(gameType = 0) {
			this.$api
				.getRaiseConfigListBend()
				.then((res) => {
					if (res?.code === 200) {
						const configData = res?.data || []
						if (gameType) {
							this.formatRaiseConfig(configData, gameType)
						} else {
							// 德州扑克
							this.formatRaiseConfig(configData, 2001)
							// 短牌
							this.formatRaiseConfig(configData, 2002)
						}
					}
				})
				.catch(() => {})
		},
		// 德州扑克取消
		handleTexasPokerCancel() {
			this.getRaiseConfig(2001)
			this.$message.info(this.$t('dxn.card_ables_list.canceled'))
		},
		// 短牌取消
		handleShortCardCancel() {
			this.getRaiseConfig(2002)
			this.$message.info(this.$t('dxn.card_ables_list.canceled'))
		}
	}
}
</script>
